<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function sendAjax() {
            // 1.创建XMLHttpRequest对象
            var xhr = new XMLHttpRequest();
            
            // 2. 对状态改变进行监听
            xhr.onreadystatechange = function(){
                // console.log(xhr.readyState)
                if(xhr.readyState == 4 && xhr.status == 200){
                    console.log(xhr.responseText)
                }

            }
 
            // 3.与服务器建立连接
            xhr.open('get','hello?username=alice',true)

            // 4.发送请求
            xhr.send()
        }
    </script>
</head>
<body>
    <!--
        传统Web请求
    -->
    <form action="hello">
        用户名：<input type="text" name="uername">
        <input type="submit" value="提交">
    </form>

    <!--
        Ajax请求
    -->
    <button onclick="sendAjax()">发送Ajax请求</button>
</body>
</html>